#####################################
# Dyadic Ratio algorithm: GERMANY   #
# Appendix table3                   #
#####################################


###load library
library(openxlsx)
library(psych)
library(ggplot2)
library(gridExtra)
library(tidyverse)

###usa macropartisanship_extract
# "extract.R" should be obtained from James Stimson's HP
# URL: https://stimson.web.unc.edu/software/
source("extract.R")

#load data
ge<-read.csv("german_extract.csv")
attach(ge)
describe(ge)
ge<-na.omit(ge)

#make tidy data by tidyverse
df_german_tidy <- ge %>%
  gather(key = VARNAME, value = value, -yearMon)

#setting time-series information
varname<-df_german_tidy$VARNAME
date<-as.Date(df_german_tidy$yearMon)
index<-df_german_tidy$value
ncases<-NULL

#using "extract" to compute macropartisanship
output_german<-extract(varname,date=date,index,ncases,begindt=ISOdate(1977,3,1),
                        enddt = ISOdate(2016,12,1), unit="M",npass=2)
display(output_german)
summary(output_german)

#factor scores of 2 dimensions
mpartisan1_german<-output_german$latent1
mpartisan2_german<-output_german$latent2
YEAR<-1977:2016







